﻿child_personality_gain_ua = { #child_personality_gain to child_personality_gain_ua
	trigger = {
		OR = {
			is_adult = no
			is_ua_adult_preadult = yes
		}
		number_of_personality_traits < personality_trait_limit
	}
	random_events = {
		100 = child_personality.0001 # craven, lazy or arbitrary
		100 = child_personality.0002 # arrogant, compassionate or callous
		100 = tgp_child_personality.0002 # arrogant, compassionate or callous
		100 = child_personality.0003 # deceitful, honest or humble
		100 = tgp_child_personality.0003 # deceitful, honest or humble
		100 = child_personality.0004 # generous, diligent or patient
		100 = tgp_child_personality.0004 # generous, diligent or patient
		100 = child_personality.0005 # wrathful, forgiving or fickle
		300 = child_personality_ua.0006 # vengeful, chaste or stubborn - Weighted x3 because it can only be triggered as the 3rd and final personality event
		100 = child_personality.0007 # just, cynical or temperate
		100 = tgp_child_personality.0007 # just, cynical or temperate
		300 = child_personality_ua.0008 # greedy, gregarious or lustful - Weighted x3 because it can only be triggered as the 3rd and final personality event
		100 = child_personality.0009 # brave, calm or zealous
		100 = tgp_child_personality.0009 # brave, calm or zealous
		100 = child_personality.0010 # ambitious, sadistic or paranoid
		100 = tgp_child_personality.0010 # ambitious, sadistic or paranoid
		100 = child_personality.0011 # content, fickle or trusting
		100 = child_personality.0012 # impatient, shy or gluttonous
		
		100 = child_personality.7000 # diligent, gregarious, temperate
		100 = tgp_child_personality.7000 # diligent, gregarious, temperate
		100 = child_personality.7010 # zealous, ambitious, sadistic
		100 = tgp_child_personality.7010 # zealous, ambitious, sadistic
		100 = child_personality.7020 # shy, paranoid, craven
		100 = tgp_child_personality.7020 # shy, paranoid, craven
		100 = child_personality.7030 # lazy, gluttonous, compassionate
		100 = tgp_child_personality.7030 # lazy, gluttonous, compassionate
		600 = child_personality_ua.7040 # lustful, chaste - Weighted x6 because it can only be triggered as the 3rd and final personality event
		600 = tgp_child_personality.7040 # lustful, chaste - Weighted x6 because it can only be triggered as the 3rd and final personality event
		100 = child_personality.7050 # just, greedy, callous
		100 = tgp_child_personality.7050 # just, greedy, callous
		100 = child_personality.7060 # humble, cynical, content
		100 = tgp_child_personality.7060 # humble, cynical, content
		100 = child_personality.7070 # vengeful, deceitful, calm
		100 = tgp_child_personality.7070 # vengeful, deceitful, calm
		100 = child_personality.7080 # generous, fickle, arrogant
		100 = tgp_child_personality.7080 # generous, fickle, arrogant
		100 = child_personality.7090 # forgiving, trusting, patient
		100 = tgp_child_personality.7090 # forgiving, trusting, patient
		100 = child_personality.7100 # honest, arbitrary, impatient
		100 = tgp_child_personality.7100 # honest, arbitrary, impatient
		100 = child_personality.7200 # brave, stubborn, wrathful
		100 = tgp_child_personality.7200 # brave, stubborn, wrathful
		10 = child_personality.7300 # eccentric, compassionate, callous
		10 = tgp_child_personality.7300 # eccentric, compassionate, callous
		10 = child_personality.7400 # eccentric, fickle, stubborn

		#In prison
		100 = child_personality_ua.0021 ##Gain lustful
		100 = child_personality_ua.0022 ##Gain chaste
		100 = child_personality.0023 ##Gain gluttonous
		100 = child_personality.0024 ##Gain temperate
		100 = child_personality.0025 ##Gain greedy
		50 = child_personality.0026 ##Gain generous
		100 = child_personality.0027 ##Gain lazy
		100 = child_personality.0028 ##Gain diligent
		100 = child_personality.0029 ##Gain wrathful
		100 = child_personality.0030 ##Gain calm
		100 = child_personality.0031 ##Gain patient
		100 = child_personality.0032 ##Gain impatient
		100 = child_personality.0033 ##Gain arrogant
		100 = child_personality.0034 ##Gain humble
		100 = child_personality.0035 ##Gain deceitful
		50 = child_personality.0036 ##Gain honest
		100 = child_personality.0037 ##Gain craven
		100 = child_personality.0038 ##Gain brave
		100 = child_personality.0039 ##Gain shy
		100 = child_personality.0040 ##Gain gregarious
		100 = child_personality.0041 ##Gain ambitious
		100 = child_personality.0042 ##Gain content
		100 = child_personality.0043 ##Gain arbitrary
		100 = child_personality.0044 ##Gain just
		100 = child_personality.0045 ##Gain cynical
		100 = child_personality.0046 ##Gain zealous
		100 = child_personality.0047 ##Gain paranoid
		50 = child_personality.0048 ##Gain trusting
		50 = child_personality.0049 ##Gain compassionate
		100 = child_personality.0050 ##Gain callous
		100 = child_personality.0051 ##Gain sadistic
		100 = child_personality.0052 ##Gain stubborn
		100 = child_personality.0053 ##Gain fickle
		100 = child_personality.0054 ##Gain vengeful
		50 = child_personality.0055 ##Gain forgiving
	}
}

childhood_ongoing_ua = { #childhood_ongoing
	trigger = {
		is_ruler = yes
		is_available_ua_adult = yes
	}
	random_events = {
		chance_to_happen = 50
		400 = 0
		800 = childhood.0001 #Child gets a crush
		100 = childhood.0003 #Child gets a friend
		100 = childhood.0005 #Child gets a bully
		100 = childhood.0007 #Child gets a victim
		100 = childhood.1000 #Your friendship can turn into a crush
		100 = childhood.1001 #You make your bully stop being such a bully
		100 = childhood.1002 #Parent is your educator, "supportive_parent" opinion_modifier
		100 = childhood.1004 #Guardian parent reduces stress
		100 = childhood.1005 #Guardian parent gives stress
		100 = childhood.1006 #Guardian parent (diligent) gives stress to lazy child
		100 = childhood.1007 #Bully gives you stress
		100 = childhood.1008 #To have a victim reduces stress
		100 = childhood.1009 #Your friend reduces your stress
		100 = childhood.1010 #Crush gives/reduces stress
		100 = childhood.1011 #Child might return an existing crush
		100 = childhood.1012 #Cruel guardian parent take child's toy away
		100 = childhood.1013 #You destroy your victims toy
		100 = childhood.1015 #child studies diplomacy with friend/crush
		100 = childhood.1016 #child studies martial with friend/crush
		100 = childhood.1017 #child studies stewardship with friend/crush
		100 = childhood.1018 #child studies intrigue with friend/crush
		100 = childhood.1019 #child studies learning with friend/crush
		50 = childhood.2001 #Get a pet cat!
		50 = childhood.2003 #Get a pet dog!
		100 = child_personality.0061 # Child may gain a propensity to drinking and lose their shyness by watching their guardian
		
		#BP1
		100 = childhood.7000 # Steal an adults clothes!
		5 = childhood.7100 # See another child get annihilated in a brutal but historically-appropriate fashion!
		100 = childhood.7200 # Try to learn the language of a Friend/crush
		100 = childhood.7300 # Beat up another child for a hook
		100 = bp1_yearly.5721 # Roast marshmallows over a fire with another child
		150 = childhood.7400 # Your bodyguard protects you from your bully
		100 = childhood.7500 # Your guardian tells you a story about one of their memories around the bonfire
		100 = bp1_yearly.9034 # You find a terrifying bog witch
		100 = bp1_yearly.9037 # You find a bog corpse
		100 = bp1_yearly.9041 # Your sibling is sad over the death of your parent
		40 = bp1_yearly.5001 # Your sibling tries to kill you

		#BP2
		300 = bp2_yearly.8100 # You develop feelings for another kid, is this a crush? 
		300 = bp2_yearly.5005 # A winsome foreign hostage
		300 = bp2_yearly.5009 # You promise?
	}
}

on_7th_birthday_ua = { #on_10th_birthday
	trigger = { age = 7 }

	events = {
		child_personality.4000 #Assigns a sexuality to the child
		#bp1_house_feud.9003
		#bp1_house_feud.9004
	}
}

on_10th_birthday_ua = { #on_15th_birthday
	trigger = { age = 10 }

	events = {
		witch.1001
		secret_faith.1001
		bp2_yearly.2019 # Imaginary Friend - Eccentric Trait Event
	}
}
# ADULTHOOD
on_12th_14th_birthday_ua = { #on_16th_birthday
	trigger = {
		is_ua_adult_exact_age = yes
	}

	events = {
		childhood_education.9103		# To make sure that every child gets a education
		child_personality.4011			# To make sure everyone gets a sexuality
		childhood.0900					# victim transforms into opinion modifier on adulthood
		childhood.0910					# bully transforms into opinion modifier on adulthood
		childhood.0998					# crush transforms into opinion modifier on adulthood
		coming_of_age.0001				# Learning
		coming_of_age.0002				# Stewardship
		coming_of_age.0003				# Martial
		coming_of_age.0004				# Intrigue
		coming_of_age.0005				# Diplomacy
		delay = { days = 2 }
		childhood_education.0005		# To remove education focus
		childhood_education.0006		# To remove stray guardians
		childhood_education.0007		# To remove childhood traits and make sure any education trait is applied
		education_trait_based_on_focus = yes
		childhood_education.9103  # Fallback if focus missing
		coming_of_age.2000				# Sage Accolade
		coming_of_age.2001				# Sage Accolade high bonus
		coming_of_age.3000				# House Knight Accolade
		coming_of_age.3011				# Junior Emperors become Co-Emperors
		court_events.3091				# Dad promised you a warhorse
		tgp_japan_yearly_events.1210    # Challenged as house head
	}

	effect = {
		if = {
			limit = {
				is_ai = yes
				# Shouldn't matter _but_, just in case, we double-check that you're actually in a suitable diarchy.
				has_diarchy_active_parameter = diarchy_type_is_entrenched_regency
			}
			trigger_event = {
				id = diarchy.0111
				months = { 6 24 }
			}
		}
		# Challenged as house head in Japan
		if = {
			limit = {
				government_is_japanese_trigger = yes  
				is_house_head = yes
			}
			trigger_event = {
				weeks = { 2 4 }
				id = tgp_japan_yearly_events.1210 
			}
		}
		#Yurt Domicile effects
		if = {
			limit = {
				warden ?= {
					government_has_flag = government_is_nomadic
					domicile ?= {
						has_domicile_building_or_higher = lifestyle_xp_yurt_03
					}
				}
			}
			warden.domicile ?= {
				switch = {
					trigger = has_domicile_parameter
					nomad_yurt_better_children_education_outcomes_lvl_1 = {
						random = {
							chance = {
								value = warden.learning
								multiply = 0.5
							}
							root = {
								add_trait = lifestyle_mystic
							}
						}
					}
					nomad_yurt_better_children_education_outcomes_lvl_2 = {
						random = {
							chance = {
								value = warden.learning
							}
							root = {
								add_trait = lifestyle_mystic
							}
						}
					}
				}
			}
		}
		# If they had the Imaginary Friend story cycle, determine if we need to end the story or assign an adult persona to the imaginary friend 
		if = {
			limit = {
				any_owned_story = { type = story_cycle_imaginary_friend }
				NOT = { has_trait = eccentric }
			}
			random_owned_story = {
				type = story_cycle_imaginary_friend
				end_story = yes
			}
			remove_character_modifier = imaginary_friend_modifier
		}
		else = {
			random_owned_story = {
				type = story_cycle_imaginary_friend
				random_list = {
					50 = { # Give them a devilish imaginary friend in adulthood
						set_variable = {
							name = imaginary_friend_disposition
							value = flag:devil
						}
						modifier = {
							root = { has_trait = sadistic }
							add = 10
						}
						modifier = {
							root = { has_trait = vengeful }
							add = 10 
						}
						modifier = {
							root = { has_trait = deceitful }
							add = 10 
						}
						modifier = {
							root = { has_trait = callous }
							add = 10 
						}
						modifier = {
							root = { has_trait = paranoid }
							add = 10 
						}
					}
					50 = { # Give them an angelic imaginary friend in adulthood
						set_variable = {
							name = imaginary_friend_disposition
							value = flag:angel 
						}
						modifier = {
							root = { has_trait = compassionate }
							add = 10 
						}
						modifier = {
							root = { has_trait = forgiving }
							add = 10 
						}
						modifier = {
							root = { has_trait = generous }
							add = 10 
						}
						modifier = {
							root = { has_trait = calm }
							add = 10 
						}
						modifier = {
							root = { has_trait = content }
							add = 10 
						}
					}
				}
			}
		}
		# Hostage reaches adulthood
		if = {
			limit = { is_hostage = yes }
			save_scope_as = hostage
			warden ?= {
				set_variable = {
					name = hook_chance
					value = scope:hostage.bp2_hostage_loyalty_hook_chance_value
				}
				trigger_event = {
					id = bp2_hostage_system.0200
					days = 5
				}
			}
		}
		#Norman adventurer creation effect
		#And swords for hire adventurers
		if = {
			limit = {
				laamp_youth_cultural_tradition_trigger = yes
			}
			trigger_event = {
				id = ep3_laamp_decision_event.1300
				years = 2
			}
		}
		#Mandala Succession effect
		if = {
			limit = { has_variable = mandala_succession_waiting_on_adulthood }
			var:mandala_succession_waiting_on_adulthood = { save_scope_as = deceased_mandala_ruler }
			trigger_event = {
				id = tgp_east_asia_mandala_events.0101
				delayed = yes
			}
		}
	}
}

on_birthday_education_events_ua = { #on_birthday_education_events
	effect = {
		save_scope_as = child
		court_owner ?= {
			save_scope_as = court_owner
			# Chance to gain extra skills if you have a Court Tutor teaching
			court_position:court_tutor_court_position ?= {
				if = {
					limit = { has_variable = court_tutor_teach_kids }
					save_scope_as = court_tutor_scope
					random = {
						chance = {
							value = 5
							add = {
								value = "aptitude(court_tutor_court_position)"
								multiply = 15
							}
						}
						if = {
							limit = {
								aptitude = {
									court_position = court_tutor_court_position
									value >= 3
								}
							}
							save_scope_value_as = {
								name = skill_boost
								value = {
									integer_range = {
										min = 1
										max = 2
									}
								}
							}
						}
						else = {
							save_scope_value_as = {
								name = skill_boost
								value = 1
							}
						}
						scope:court_tutor_scope = {
							random_list = {
								1 = {
									modifier = {
										add = 1
										diplomacy > decent_skill_rating
									}
									save_temporary_scope_as = diplomacy_tutor
								}
								1 = {
									modifier = {
										add = 1
										martial > decent_skill_rating
									}
									save_temporary_scope_as = martial_tutor
								}
								1 = {
									modifier = {
										add = 1
										stewardship > decent_skill_rating
									}
									save_temporary_scope_as = stewardship_tutor
								}
								1 = {
									modifier = {
										add = 1
										learning > decent_skill_rating
									}
									save_temporary_scope_as = learning_tutor
								}
							}
						}
						scope:court_owner ?= {
							send_interface_toast = {
								type = event_royal_court_good
								title = court_tutor_teach_kids_title
								left_icon = scope:child
								right_icon = scope:court_tutor_scope
								if = {
									limit = { this = scope:child }
									custom_tooltip = court_tutor_teach_kids_notification_desc_you
								}
								else = { custom_tooltip = court_tutor_teach_kids_notification_desc }
								scope:child = {
									switch = {
										trigger = exists
										scope:diplomacy_tutor = { add_diplomacy_skill = scope:skill_boost }
										scope:martial_tutor = { add_martial_skill = scope:skill_boost }
										scope:stewardship_tutor = { add_stewardship_skill = scope:skill_boost }
										scope:learning_tutor = { add_learning_skill = scope:skill_boost }
									}
								}
							}
						}
					}
				}
			}

			# Chance to gain extra skills if you have a Court Guru teaching
			court_position:court_guru_court_position ?= {
				if = {
					limit = { has_variable = court_tutor_teach_kids }
					save_scope_as = court_tutor_scope
					random = {
						chance = {
							value = 5
							add = {
								value = "aptitude(court_guru_court_position)"
								multiply = 15
							}
						}
						if = {
							limit = {
								aptitude = {
									court_position = court_guru_court_position
									value >= 3
								}
							}
							save_scope_value_as = {
								name = skill_boost
								value = {
									integer_range = {
										min = 1
										max = 2
									}
								}
							}
						}
						else = {
							save_scope_value_as = {
								name = skill_boost
								value = 1
							}
						}
						scope:court_tutor_scope = {
							random_list = {
								1 = {
									modifier = {
										add = 1
										diplomacy > decent_skill_rating
									}
									save_temporary_scope_as = diplomacy_tutor
								}
								1 = {
									modifier = {
										add = 1
										martial > decent_skill_rating
									}
									save_temporary_scope_as = martial_tutor
								}
								1 = {
									modifier = {
										add = 1
										stewardship > decent_skill_rating
									}
									save_temporary_scope_as = stewardship_tutor
								}
								1 = {
									modifier = {
										add = 1
										learning > decent_skill_rating
									}
									save_temporary_scope_as = learning_tutor
								}
							}
						}
						scope:court_owner ?= {
							send_interface_toast = {
								type = event_royal_court_good
								title = court_tutor_teach_kids_title
								left_icon = scope:child
								right_icon = scope:court_tutor_scope
								if = {
									limit = { this = scope:child }
									custom_tooltip = court_tutor_teach_kids_notification_desc_you
								}
								else = { custom_tooltip = court_tutor_teach_kids_notification_desc }
								scope:child = {
									switch = {
										trigger = exists
										scope:diplomacy_tutor = { add_diplomacy_skill = scope:skill_boost }
										scope:martial_tutor = { add_martial_skill = scope:skill_boost }
										scope:stewardship_tutor = { add_stewardship_skill = scope:skill_boost }
										scope:learning_tutor = { add_learning_skill = scope:skill_boost }
									}
								}
							}
						}
					}
				}
			}
		}
	}

	events = {
		court_maintenance_ua.0000 #All children should acquire Personality Traits
	}
	
	on_actions = {
		childhood_education_boost
		childhood_education_ua
	}
}

#To gain education points
childhood_education_ua = { #childhood_education
	events = {
		childhood_education.9002
		childhood_education.1001
		childhood_education_ua.9004
		childhood_education.9010
	}
	on_actions = {
		childhood_education_patronage
	}
}